package light.head.dao.el;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Service;

import light.head.dto.ExamTopic;
import light.head.framework.base.BaseDAO;
import light.head.model.el.AnswerRecord;
@Service
public class AnswerRecordDAO extends BaseDAO<AnswerRecord, Integer>{
private final static String findByTrcAndErcAndTc = "FROM AnswerRecord ar WHERE ar.trc = ? AND ar.erc = ? AND ar.tc = ?";
	
	/**
	 * 通过 考试记录编号和考试题目编号找到 答题记录
	 */
	public List<AnswerRecord> findByTrcAndErcAndTc(Integer trc,Integer erc,Integer tc){
		if(trc != null || erc != null && tc != null){
			return findI(findByTrcAndErcAndTc, trc,erc,tc);
		}
		return null;
	}
	
	/**
	 * 获取指定考试记录的答案记录 并填充到题目
	 * erc 考试记录编号
	 * @return
	 */
	public void addAnswerRecordByErc(Integer erc, List<ExamTopic> list){
		if(erc != null && list != null && list.size() > 0){
			String sql = "FROM AnswerRecord ar WHERE ar.erc = ?";
			List<AnswerRecord> arList = find(sql, erc);
			List<AnswerRecord> itemList = null;
			for(ExamTopic et : list){
				itemList = new ArrayList<AnswerRecord>();
				for(AnswerRecord ar : arList){
					if(et.getCode().intValue() == ar.getTc().intValue()){
						itemList.add(ar);
					}
				}
				et.setArList(arList);
			}
		}
	}
	
}
